# -*- coding: utf-8 -*-
# @Time : 2021/9/13 10:40
# @Author : 阿怪
# @Email : 673691277@qq.com
# @File : contract_page.py
# @Project : crm自动化测试项目实战
'''合同页面类'''


from selenium.webdriver.common.by import By
from page.base_page import BasePage
import time

today = time.strftime('%Y-%m-%d')  # 获取当前日期
from utils.util import HOST2

class ContractPage(BasePage):
    '''合同页面类'''


    #定义定位器
    url = '{}/index.php?m=contract'.format(HOST2)
    add_contract_locator = (By.XPATH,'/html/body/div[5]/div[2]/div[1]/div/a')  #【添加合同】定位器
    busop_locator = (By.XPATH,'//*[@id="business_name"]')  #【来源商机】定位器
    newest_busop_locator = (By.CSS_SELECTOR,'#data > tr:nth-child(1) > td:nth-child(1) > input[type=radio]:nth-child(1)') #最新商机定位器
    clickok_locator = (By.XPATH,'/html/body/div[7]/div[3]/div/button[1]/span')  #选择商机界面，点击OK
    submitclick_locator = (By.NAME,'submit')  #点击【保存】
    checkall_locator = (By.ID,'check_all')   #全选按钮定位器
    delete_locator= (By.XPATH,'//*[@id="delete"]')   #删除按钮定位器

    #操作元素方法
    def add_contract(self):
        '''点击【添加合同】'''
        element= self.driver.find_element(*self.add_contract_locator)
        element.click()

    def click_business(self):
        '''点击来源商机'''
        element = self.driver.find_element(*self.busop_locator)
        element.click()  # 点击【来源商机】

    def choice_business(self, business_name):
        '''默认选择最新商机'''
        element1 = self.driver.find_element(*business_name)  # 默认选择最新那条商机
        element1.click()


    def click_ok(self):
        '''选择商机界面，点击OK'''
        element2 = self.driver.find_element(*self.clickok_locator)
        element2.click()

    def edit_contract(self,business_name=newest_busop_locator):
        '''编辑添加合同'''
        self.click_business()
        self.choice_business(business_name)
        self.click_ok()



    def submit_click(self):
        '''保存新建合同'''
        element= self.driver.find_element(*self.submitclick_locator)
        element.click()

    def click_checkall(self):
        '''点击全选'''
        self.driver.find_element(*self.checkall_locator).click()

    def click_delete(self):
        '''点击删除'''
        self.driver.find_element(*self.delete_locator).click()

    def clear_con(self):
        '''删除所有合同'''
        self.click_checkall()
        self.click_delete()
        self.alert()





